package cc.wsyw126.java.nowcoder.offerdidi.two;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

/**
 * Created by dp on 2017/4/22.
 */
public class Main {
    public static void main(String[] args) {
        Main one = new Main();
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            String s = sc.nextLine();
            Integer integer = Integer.valueOf(s);
            ArrayList<node> nodes = new ArrayList<>();
            for (int i = 0; i < integer; i++) {
                String s1 = sc.nextLine();
                String[] split = s1.split(" ");
                node node = one.new node(Integer.valueOf(split[0]), Integer.valueOf(split[1]));
                nodes.add(node);
            }
            Collections.sort(nodes, new Comparator<node>() {
                @Override
                public int compare(node o1, node o2) {
                    return o1.x - o2.x;
                }
            });
            int max = 1;
            int my = doCal(nodes, 1, 0);
            max = my > max ? my : max;
            System.out.println(max);
        }
    }

    private static int doCal(ArrayList<node> nodes, int low, int campare) {
        if (low >= nodes.size()) return 1;
        if (nodes.get(campare).x < nodes.get(low).x && nodes.get(campare).y < nodes.get(low).y) {
            int no = doCal(nodes, low + 1, campare);
            int yes = doCal(nodes, low + 1, low) + 1;
            return no > yes ? no : yes;
        } else {
            return doCal(nodes, low + 1, campare);
        }
    }

    private class node {
        private int x;
        private int y;

        public node(int x, int y) {
            this.x = x;
            this.y = y;
        }
    }


}
